package com.three.controller;

import com.three.utils.Doc2HtmlUtil;
import org.apache.commons.io.IOUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletOutputStream;
import javax.servlet.ServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

@Controller
public class Test02 {

    @RequestMapping("to")
    public  void main(ServletResponse response) {
        long startTime = System.currentTimeMillis();
        Doc2HtmlUtil doc2HtmlUtil=new Doc2HtmlUtil();
        File file = new File("src/main/java/com/three/controller/日志填写步骤.docx");//需要转换的文件
        try {
            File docx = Doc2HtmlUtil.file2pdf(new FileInputStream(file), "D://", "docx");
            //写回
            ServletOutputStream outputStream = response.getOutputStream();
            InputStream in = new FileInputStream(docx);// 读取文件
            // copy文件
            IOUtils.copy(in, outputStream);
        } catch (Exception e) {
            e.printStackTrace();
        }
        long endTime = System.currentTimeMillis();
        System.out.println("程序运行时间：" + (endTime - startTime) + "ms");
    }
}
